<?php 

class Sitemap_Bootstrap extends Zend_Application_Module_Bootstrap
{
    /**
     * Seting resources
     *
     */
    protected function _initResources()
    {
        $resources=Zend_Registry::get('resources');
        
        $resources[]=Sitemap_Model_Sitemap::RESOURCE_NAME; // sitemap resource
        
        Zend_Registry::set('resources', $resources);
        
        Zend_Registry::get('access')->addResource(Sitemap_Model_Sitemap::RESOURCE_NAME);
    }
    
    /**
     * Initializing access permissions
     *
     * @return object
     */
    protected function _initAccess()
    {
        $access=Zend_Registry::get('access');

        //seting access permissions for resource
        $access->allow(Application_Model_UserRoles::getDefaultRole(),Sitemap_Model_Sitemap::RESOURCE_NAME,Application_Model_UserPerms::VIEW_PERM); // allow everybody to view
        
    }
    
    protected function _initRoute()
    {
        $module='sitemap';
        
        $routes=array(
                    'sitemap',
                    'sitemap/:key',
                    'sitemap.xml'
                    );
                    
        foreach ($routes as $id=>$route)
        {
            $controller='index';
            $action=($id==2) ? 'xml' : 'index';
            
            Zend_Registry::get('router')->addRoute($module.$controller.$action.$id, 
                                new Zend_Controller_Router_Route($route,array(
                                    'controller' => $controller,
                                    'action' => $action,
                                    'module' => $module
                                ))
                            ); 
                            
            Zend_Registry::get('router')->addRoute($module.$controller.$action.$id.'language', 
                                new Zend_Controller_Router_Route(':language/'.$route,array(
                                    'controller' => $controller,
                                    'action' => $action,
                                    'module' => $module
                                ))
                            );
        }
    }
}
